<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjrq">
              <j-date placeholder="请选择数据日期" v-model="model.sjrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="识别码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sbm">
              <a-input v-model="model.sbm" placeholder="请输入识别码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="存款人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zqrxm">
              <a-input v-model="model.zqrxm" placeholder="请输入存款人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ywlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择业务类型"
                v-model="model.ywlx"
                dict="llbb_param_config,name,code"
                pidValue="1504633419996971009"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择客户类型"
                v-model="model.khlx"
                dict="llbb_param_config,name,code"
                pidValue="1504633122197192706"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="开户单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khdw">
              <a-input v-model="model.khdw" placeholder="请输入开户单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="开户证件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khzjlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择开户证件类型"
                v-model="model.khzjlx"
                dict="llbb_param_config,name,code"
                pidValue="1486532284505436162"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="开户证件号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khzjhm">
              <a-input v-model="model.khzjhm" placeholder="请输入开户证件号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="开户证件有效期限" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khzjyxqx">
              <a-input v-model="model.khzjyxqx" placeholder="请输入开户证件有效期限"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="存款账户类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ckzhlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择存款账户类型"
                v-model="model.ckzhlx"
                dict="llbb_param_config,name,code"
                pidValue="1486579604118876161"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="存款状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ckzt">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择存款状态"
                v-model="model.ckzt"
                dict="llbb_param_config,name,code"
                pidValue="1486525621136306177"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="存款产品类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ckcplb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择存款产品类别"
                v-model="model.ckcplb"
                dict="llbb_param_config,name,code"
                pidValue="1486523931192504322"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="存款账户号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ckzhhm">
              <a-input v-model="model.ckzhhm" placeholder="请输入存款账户号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="存款本金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ckbj">
              <a-input-number v-model="model.ckbj" placeholder="请输入存款本金" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="应付利息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yflx">
              <a-input-number v-model="model.yflx" placeholder="请输入应付利息" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="本息合计" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bxhj">
              <a-input-number v-model="model.bxhj" placeholder="请输入本息合计" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <a-input v-model="model.bz" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <Mechanism v-model="model.nbjgh"></Mechanism>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import Mechanism from '@/components/Mechanism'

  export default {
    name: 'CdCrFiscalDepositForm',
    components: {
      Mechanism
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          sjrq: [
            { required: true, message: '请选择数据日期!'},
          ],
          sbm: [
            { required: true, message: '请输入识别码!'},
          ],
          zqrxm: [
            { required: true, message: '请输入存款人姓名!'},
          ],
          ywlx: [
            { required: true, message: '请选择业务类型!'},
          ],
          khlx: [
            { required: true, message: '请选择客户类型!'},
          ],
          khdw: [
            { required: true, message: '请输入开户单位!'},
          ],
          khzjlx: [
            { required: true, message: '请选择开户证件类型!'},
          ],
          khzjhm: [
            { required: true, message: '请输入开户单位证件号码!'},
          ],
          ckzhlx: [
            { required: true, message: '请选择存款账户类型!'},
          ],
          ckzt: [
            { required: true, message: '请选择存款状态!'},
          ],
          ckcplb: [
            { required: true, message: '请选择存款产品类别!'},
          ],
          ckzhhm: [
            { required: true, message: '请输入存款账户号码!'},
          ],
          ckbj: [
            { required: true, message: '请输入存款本金!'},
          ],
          yflx: [
            { required: true, message: '请输入应付利息!'},
          ],
          bxhj: [
            { required: true, message: '请输入本息合计!'},
          ],
        },
        url: {
          add: "/cdCrFiscalDeposit/cdCrFiscalDeposit/add",
          edit: "/cdCrFiscalDeposit/cdCrFiscalDeposit/edit",
          queryById: "/cdCrFiscalDeposit/cdCrFiscalDeposit/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>